<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <span th:include="~{include::mycss}"></span>
    <script>
        $(function (){
            //全选
            $("#all").click(function (){
                $("[name='chk']").prop("checked",this.checked);
            })
            //删除
            $(".btn-warning").click(function (){
                //判断
                let arr= $("[name='chk']:checked");
                if(arr.length==0){
                    alert("请选择要删除的商品");
                }else {
                    if (confirm("确认要删除吗？")) {
                        //删除
                        let str = "";
                        for (let i = 0; i < arr.length; i++) {
                            str += arr[i].value + ",";
                        }
                        alert(str);
                        $.ajax({
                            url: "/delete",
                            type: "get",
                            data: {
                                "gids": str
                            },
                            success: function (data) {
                                alert(data);
                                location.reload();
                            }
                        })
                    }
                }
            })
        })
    </script>

</head>
<body>
          <div class="container">
             <table class="table table-hover table-bordered">
                 <tr>
                     <td>
                         <input type="checkbox" id="all">
                         <button class="btn btn-warning">删除</button>
                     </td>
                     <td>商品名称</td>
                     <td>商品单价</td>
                     <td>商品描述</td>
                     <td>商品数量</td>
                     <td>
                         操作
                     </td>
                 </tr>
               <tr th:each="cart:${session.shoppingCart}" th:object="${cart}">
                   <td>
                       <input type="checkbox" name="chk" th:value="*{goods.gid}">
                   </td>
                   <td th:text="*{goods.gname}"></td>
                   <td th:text="*{goods.price}"></td>
                   <td th:text="*{goods.gdesc}"></td>
                   <td th:text="*{count}"></td>

               </tr>
                 <tr>
                     <td colspan="10" align="center">
                          <a href="javascript:history.go(-1)">继续购物</a>

                          订单总价：￥<span th:text="${session.total}"></span>元。
                           <button class="btn btn-primary" onclick="location='pay'">结账</button>
                     </td>
                 </tr>
             </table>
          </div>
</body>
</html>
